home *** CD-ROM | disk | FTP | other *** search
/ Multimedia Jumpstart / Multimedia Microsoft Jumpstart Version 1.1a (Microsoft).BIN / develpmt / examples / infobrws / src / libentry.asm < prev    next >
Encoding:
Assembly Source File  |  1990-04-19  |  2.2 KB  |  69 lines

  1. PAGE,132
  2. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3. ;
  4. ;       LIBENTRY.ASM
  5. ;
  6. ;       Windows dynamic link library entry routine
  7. ;
  8. ;   This module generates a code segment called INIT_TEXT.
  9. ;   It initializes the local heap if one exists and then calls
  10. ;   the C routine LibMain() which should have the form:
  11. ;   BOOL FAR PASCAL LibMain(HANDLE hInstance,
  12. ;                           WORD   wDataSeg,
  13. ;                           WORD   cbHeap,
  14. ;                           LPSTR  lpszCmdLine);
  15. ;        
  16. ;   The result of the call to LibMain is returned to Windows.
  17. ;   The C routine should return TRUE if it completes initialization
  18. ;   successfully, FALSE if some error occurs.
  19. ;
  20. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  21.  
  22. include cmacros.inc
  23.  
  24. sBegin  CODE
  25. assumes CS,CODE
  26.  
  27. ?PLM=0                           ; 'C'naming
  28. externA  <_acrtused>             ; ensures that Win DLL startup code is linked
  29.  
  30. ?PLM=1                           ; 'PASCAL' naming
  31. externFP <LibMain>               ; the C routine to be called
  32. externFP <LocalInit>             ; Windows heap init routine
  33.  
  34. cProc   LibEntry, <PUBLIC,FAR>   ; entry point into DLL
  35.  
  36. cBegin
  37.         push    di               ; handle of the module instance
  38.         push    ds               ; library data segment
  39.         push    cx               ; heap size
  40.         push    es               ; command line segment
  41.         push    si               ; command line offset
  42.  
  43.         ; if we have some heap then initialize it
  44.         jcxz    callc            ; jump if no heap specified
  45.  
  46.         ; call the Windows function LocalInit() to set up the heap
  47.         ; LocalInit((LPSTR)start, WORD cbHeap);
  48.         
  49.         xor     ax,ax
  50.         cCall   LocalInit <ds, ax, cx>
  51.         or      ax,ax            ; did it do it ok ?
  52.         jz      error            ; quit if it failed
  53.  
  54.         ; invoke the C routine to do any special initialization
  55.  
  56. callc:
  57.         call    LibMain          ; invoke the 'C' routine (result in AX)
  58.         jmp short exit           ; LibMain is responsible for stack clean up
  59.  
  60. error:  add     sp,10            ; clean up stack on a LocalInit error
  61.  
  62. exit:
  63.  
  64. cEnd
  65.  
  66. sEnd    CODE
  67.  
  68. end LibEntry
  69.